<?php



namespace App\Http\Requests\ApiV2;

use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;

class WishRequest extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title' => 'required|max:120',
            'thumb' => 'required',
            'thumb_small' => 'required',
            'point'=>'required'
        ];
    }

    public function messages()
    {
        return [
            'title.required' => __('请输入心愿的标题'),
            'thumb.required' => __('请输入心愿的封面'),
            'point.required' => __('请输入心愿的积分'),
            'thumb_small.required' => __('请输入心愿的封面'),

        ];
    }

    public function filldata()
    {

        $user = Auth::user();
        $data = [
            'user_id'=>(int)$user['id'],
            'title' =>(string) $this->input('title'),
            'start_at' =>$this->input('start_at'),
            'thumb' =>(string) $this->input('thumb'),
            'thumb_small' =>(string) $this->input('thumb_small'),
            'point'=>$this->input('point'),
        ];

        if ($this->isMethod('post')) { // 假设POST表示创建，PUT/PATCH表示更新
            $data['remain_point'] = $this->input('point');
        }
        return $data;
    }
}
